! Huistaak TWS 1
!
! Roel Matthysen
! s0202264
! 1e Master Wiskundige Ingenieurstechnieken
!
! M_stats
! gespendeerde tijd: 1 uur en 1 kwartier
!
! getest met gfortran version 4.7.0, G95 version 0.92, 
! gfortran -o M_stats M_stats.f95
! g95 -o M_stats M_stats.f95
!
!

! Begin programma 
program M_stats

! Parameters
implicit none
real, dimension(4,4), target :: something_special = reshape( (/ &
1.0000e+00, 1.2500e-01, 1.8750e-01, 8.1250e-01, &
3.1250e-01, 6.8750e-01, 6.2500e-01, 5.0000e-01, &
5.6250e-01, 4.3750e-01, 3.7500e-01, 7.5000e-01, &
2.5000e-01, 8.7500e-01, 9.3750e-01, 6.2500e-02 &
/), (/ 4,4 /), order=(/2,1/) )

real, dimension(-3:3,0:2), target :: different_special = reshape( (/ & 
9.0909e-01,1.9091e+00,8.1818e-01,1.4545e+00,4.5455e-01, &
1.2727e+00,1.8182e-01,2.7273e-01,3.6364e-01,6.3636e-01, &
1.0000e+00,1.3636e+00,1.6364e+00,1.7273e+00,1.8182e+00, &
7.2727e-01,1.5455e+00,5.4545e-01,1.1818e+00,9.0909e-02, &
1.0909e+00 /), (/7,3/), order=(/1,2/) )


! Pointers worden gebruikt om de indices te behouden
real, dimension(:,:), pointer :: A(:,:),B(:,:)
A => something_special
B => different_special
print *, 'Info for matrix A'
call printstats(A)
print *, 'Info for matrix B'
call printstats(B)


contains

subroutine printstats(M)
real, dimension(:,:), pointer :: M
integer :: i
! Eigenschappen van de M afprinten
print *, 'Aantal rijen: ', size(M,1)
print *, 'Aantal kolommen: ', size(M,2)
print *, 'Aantal elementen: ', size(M,1)*size(M,2)
print *, 'Grootste waarde in matrix: ', maxval(M)
print *, 'Kleinste waarde in matrix: ', minval(M)
print "(a17,I2,a2,I2)", 'Bereik kolommen ',lbound(M,1),' :',ubound(M,1) 
print "(a13,I2,a2,I2)", 'Bereik rijen', lbound(M,2),' :',ubound(M,2)
! som vd rijen
do i = lbound(M,1) , ubound(M,1)
print *, "Som rij ", i, ": ", sum(M(i,:)) 
end do
! som vd kolommen
do i = lbound(M,2) , ubound(M,2)
print *, "Som kolom ", i, ": ", sum(M(:,i))
end do

end subroutine printstats

end program